//改变默认地址
function setaddress(obj){
	var addressid  = $(obj).parents('.user-addresslist').attr('cid');
	$.post("/API/Address/changedefault",{"addressid":addressid},function(res){
		if (res.status==true) {
			$(obj).parents('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");

			$(obj).parents('.user-addresslist').siblings().find(".deftip").addClass("hidden");
			$(obj).parents('.user-addresslist').find(".deftip").removeClass("hidden");

			$(obj).parents('.user-addresslist').siblings().find(".new-addr-btn a").first().removeClass('hidden');
			$(obj).parents('.user-addresslist').find(".new-addr-btn a").first().addClass('hidden');
			$(obj).parents('.user-addresslist').siblings().find(".new-addr-btn span").first().removeClass('hidden');
			$(obj).parents('.user-addresslist').find(".new-addr-btn span").first().addClass('hidden');
		}
	});
	
}
//选取地址，改变订单的地址
$("#address-list-box li").click(function(){
	//获取收货人
	var consignor = $(this).find('.buy-user').html();
	//获取收货人电话
	var telephone = $(this).find('.buy-phone').html();
	//获取收货人的地址信息
	var province = $(this).find('.province').html();
	var city = $(this).find('.city').html();
	var dist = $(this).find('.dist').html();
	var street = $(this).find('.street').html();
	$(".pay-address").find('.province').html(province);
	$(".pay-address").find('.city').html(city);
	$(".pay-address").find('.dist').html(dist);
	$(".pay-address").find('.street').html(street);
	$(".pay-address").find('.buy-user').html(consignor);
	$(".pay-address").find('.buy-phone').html(telephone);
});
//生成用户订单信息
function success(){
	
	var paylist = new Array();
	var goodslist = new Array();
	//获取总价
	var payprices = $("#pay-prices").html();
	//获取收货地址相关信息
	var addressid = $('.defaultAddr').attr("cid");
	//获取商品信息
	$(".bundle-main ul").each(function(){
		var goodsid =$(this).attr("cid");
		goodslist.push(goodsid);
		var number  = $(this).find(".sl").html()
		goodslist.push(number);
		paylist.push(goodslist);
		goodslist = [];
	});
	$.post("/API/Shopcart/createorder",{"goodslist":paylist,"addressid":addressid,"payprices":payprices},function(res){
		if (res.status==true) {
			 window.location.href="success.html?orderid="+res.data;
		}else{
			alert("创建订单失败")
		}
	})

	//alert(addressid);
}